package cn.news.xinhuanet.lottery.pool;

import cn.news.xinhuanet.utils.ToolUtils;

/**
 * 生成一个下标
 * 默认是随即生成下标
 * 也可是顺序生成
 * Created by xinhuanet on 16-2-14.
 */
public class PrizeIndex {

    private static Boolean randomIndex = true;
    private static Integer currentIndex = 0;

    /**
     * 返回一个奖品下标
     *
     * @param size
     * @return
     */
    public static Integer getPrizeIndex(Integer size) {

        //随即生成
        if (randomIndex == true) {
            currentIndex = ToolUtils.getRandomInt(size);
        } else {
            currentIndex++;
            //顺序生成
            if (currentIndex >= size) {
                currentIndex = 0;
            }
        }
        return currentIndex;
    }

    public static Boolean getRandomIndex() {
        return randomIndex;
    }

    public static void setRandomIndex(Boolean randomIndex) {
        PrizeIndex.randomIndex = randomIndex;
    }

    public static Integer getCurrentIndex() {
        return currentIndex;
    }

    public static void setCurrentIndex(Integer currentIndex) {
        PrizeIndex.currentIndex = currentIndex;
    }

    public static void main(String[] args) {
        setRandomIndex(false);
        for (int i = 0; i < 10; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int k = 0; k < 100; k++) {
                        System.out.println(getPrizeIndex(10));
                    }
                }
            }).start();
        }
    }
}
